<template>
	<view class="myWallet">
		<view class="wallet_amount">
			<view class="wallet_amount_num">
				<view class="wallet_amount_num_fir my-pdl-15">
					<view class="left_wallet">
						<view class="wallet_amount_num_fir_txt my-pdt-10">账户余额(元)</view>
						<view class="wallet_amount_num_fir_jine">{{balanceTwo.toFixed(2)||0}}</view>
					</view>
					<view class="right_wallet" @click="goSumm">
						汇总查看
					</view>
				</view>
				<view class="wallet_amount_num_two">
					<view class="tady my-pdl-15">
						<view class="fir_box">今日收益</view>
						<view class="two_box">{{todayAmount.toFixed(2) || 0}}</view>
					</view>
					<view class="cumulative">
						<view class="fir_box">累计收益</view>
						<view class="two_box">{{totalAmount.toFixed(2) || 0}}</view>
					</view>
				</view>
			</view>
			<view class="wallet_tab_box">
				<view class="wallet_tab_box_bind" @click="gowithdraw">
					<image src="https://hxc-pay.oss-cn-shenzhen.aliyuncs.com/GyrEMeCSIk_want_rawal.png" mode=""></image>
					<text class="my-mg-10">我要提现</text>
				</view>
				<view class="wallet_tab_box_bind" @click="goRecord">
					<image src="https://hxc-pay.oss-cn-shenzhen.aliyuncs.com/kmqIlDadEG_withdrawal_record.png" mode=""></image>
					<text class="my-mg-10">提现记录</text>
				</view>
			</view>
		</view>
		<view class="billing_details my-mgt-15">
			<view class="billing_details_top my-pdlr-15">
				<view class="">
					<view class="billing_details_top_txt my-mgb-10">账单明细</view>
					<view class="billing_details_top_time">
						<picker mode="date" fields="month" @change="onEnd">
							<view class="date">
								<text class="my-mgr-10">{{endDate||0}}</text>
								<image src="https://hxc-pay.oss-cn-shenzhen.aliyuncs.com/PILJTnpizY_top_select.png" style="width: 20rpx;height: 20rpx;"></image>
							</view>
						</picker>
					</view>
				</view>
				<view class="">
					<view class="spending my-mgb-10">支出：￥{{expendAmount||0}}</view>
					<view class="income">收入：￥{{revenueAmount || 0}}</view>
				</view>
			</view>
			<view class="detlias_list my-pdlr-15">
				<view class="bor" v-for="(item,index) in dev" :key="index">
					<view class="detlias_list_txt">
						<view class="txt">
							<text class="my-mgr-15">{{item.billType}}</text>
						</view>
						<view class="time">{{item.createDate}}</view>
					</view>
					<view class="detlias_list_num my-pdl-10">
						<view class="fir num_red num_black">{{item.amount||0}}</view>
						<view class="two">余额：{{item.changeAfterAmount}}</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup v-model="realName" mode="center" border-radius="20">
			<view class="realName_box">
				<view class="titl_box">
					<view class="name">实名认证</view>
					<image @click="realName=false" src="https://hxc-pay.oss-cn-shenzhen.aliyuncs.com/aYUwDbroiD_open_icon.png" mode="" style="width: 28rpx;height: 28rpx;"></image>
				</view>
				<view class="txt">
					您还没有绑定身份信息，为保障您的资金
					安全请及时绑定。
				</view>
				<view class="btn_box" @click="goRealNameAuto">去实名</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import { mywalletApi ,mytotalbillApi ,mypersonalbillApi } from "@/api/home.js"
	import { createNamespacedHelpers } from "vuex";
	const { mapState,mapActions } = createNamespacedHelpers( "my");
	export default {
		data() {
			return {
				endDate:null,
				pageIndex:0,//页数
				pageSize:30,//条数
				expendAmount:0,//支出
				revenueAmount:0,//收入
				realName:false,
				dev:[],
				total:1,
			};
		},
		onLoad() {
			this.getPersonalData()
			this.gettotalData()
			this.getPersonalBill()
		},
		created() {
			this.getDate()
		},
		// 上拉加载更多
		onReachBottom() {
			this.getPersonalBill()
		},
		computed:{
			...mapState(["balanceTwo","todayAmount","totalAmount","realNameAuthTwo","openBank"])
		},
		methods:{
			...mapActions(["getPersonalData"]),
			// 获取选中时间
			onEnd(e) {
				this.endDate = e.target.value
				this.dev=[]
				this.gettotalData()
				this.getPersonalBill()
			},
			getDate() {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				month = month > 9 ? month : '0' + month;
				this.endDate = `${year}-${month}`;
			},
			goRealNameAuto(){
				uni.navigateTo({
					url:'/pages/my/realNameAuthentication'
				})
			},
			goSumm(){
				uni.navigateTo({
					url:'/pages/main/childPages/summaryLook'
				})
			},
			// 获取汇总数据
			async gettotalData(){
				let params = {
					billTime:this.endDate,
					pageIndex:this.pageIndex,
					pageSize:this.pageSize
				}
				uni.showLoading({
					title: "正在加载中...."
				})
				const res = await mytotalbillApi(params)
				if(res.statusCode === 200){
					uni.hideLoading()
					this.expendAmount = res.data.data.expendAmount
					this.revenueAmount = res.data.data.revenueAmount
				}
			},
			//获取个人收益
			async getPersonalBill(){
				if (this.dev.length >= this.total){
					uni.showToast({
						title:"没有更多数据了",
						icon:"none"
					})
					return
				}
				let params = {
					billTime:this.endDate,
					pageIndex:this.pageIndex,
					pageSize:this.pageSize
				}
				uni.showLoading({
					title: "正在加载中...."
				})
				const res = await mypersonalbillApi(params)
				if(res.statusCode === 200){
					uni.hideLoading()
					this.dev = [...this.dev,...res.data.data.rows]
					this.total = res.data.data.total
					this.pageIndex++
				}
			},
			// 提现
			gowithdraw(){
				if(this.realNameAuthTwo){//实名认证
					if(!this.openBank){
						
						uni.showToast({
							title:"暂未开放",
							icon:"none"
						})
						return;
					}
					uni.navigateTo({
						url:"/pages/main/childPages/withdrawal"
					})
				}else{
					this.realName = true
				}
			},
			// 提现记录
			goRecord(){
				uni.navigateTo({
					url:"/pages/main/childPages/withdrawalRecord"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.myWallet{
		width: 100%;
		height: 100vh;
		background: #FAFAFA;
		.wallet_amount{
			width: 100%;
			height: 500rpx;
			background: #FFFFFF;
			.wallet_amount_num{
				width: 690rpx;
				height: 340rpx;
				margin: auto;
				background: linear-gradient(221deg, #C19C72 0%, #D5B28A 100%);
				box-shadow: 0rpx 18rpx 10rpx 0rpx rgba(193, 156, 114, 0.1);
				border-radius: 20rpx;
				.wallet_amount_num_fir{
					width: 100%;
					height: 170rpx;
					display: flex;
					align-items: center;
					.left_wallet{
						width: 67%;
						height: 100%;
						.wallet_amount_num_fir_txt,.wallet_amount_num_fir_jine{
							width: 100%;
							height: 50%;
							line-height: 85rpx;
							color: #FFFFFF;
						}
						.wallet_amount_num_fir_txt{
							font-size: 26rpx;
							font-weight: 500;
							
						}
						.wallet_amount_num_fir_jine{
							font-size: 60rpx;
							font-weight: bold;
						}
					}
					.right_wallet{
						width: 180rpx;
						height: 70rpx;
						background: #FFFFFF;
						border-radius: 35rpx;
						text-align: center;
						line-height: 70rpx;
						font-size: 26rpx;
						font-weight: bold;
						color: #C39F75;
					}
				}
				.wallet_amount_num_two{
					width: 100%;
					height: 170rpx;
					display: flex;
					align-items: center;
					.tady,.cumulative{
						width: 50%;
						height: 100%;
						.fir_box,.two_box{
							width: 100%;
							color: #FFFFFF;
						}
						.fir_box{
							height: 80rpx;
							line-height: 100rpx;
							font-size: 26rpx;
							font-weight: 500;
						}
						.two_box{
							height: 90rpx;
							font-size: 36rpx;
							font-weight: bold;
							
						}
					}
				}
			}
			.wallet_tab_box{
				width: 100%;
				height: 158rpx;
				display: flex;
				align-items: center;
				justify-content: space-around;
				.wallet_tab_box_bind{
					display: flex;
					align-items: center;
					font-size: 28rpx;
					font-weight: 500;
					color: #000000;
					image{
						width: 32rpx;
						height: 32rpx;
					}
				}
			}
		}
		.billing_details{
			width: 100%;
			height: 654rpx;
			background: #FFFFFF;
			.billing_details_top{
				width: 100%;
				height: 140rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1rpx solid #E8E8E8;
				.billing_details_top_txt{
					font-size: 30rpx;
					font-weight: bold;
					color: #000000;
				}
				.billing_details_top_time{
					font-size: 30rpx;
					font-weight: 500;
					color: #333333;
				}
				.spending,.income{
					font-size: 24rpx;
					font-weight: 400;
					color: #000000;
				}
			}
			.detlias_list{
				width: 100%;
				height: 150rpx;
				.bor{
					width: 100%;
					height: 100%;
					display: flex;
					align-items: center;
					border-bottom: 1rpx solid #F2F2F2;
				}
				.detlias_list_txt{
					width: 70%;
					height: 100%;
					.txt,.time{
						width: 100%;
						height: 50%;
						
					}
					.txt{
						font-size: 32rpx;
						font-weight: 500;
						color: #333333;
						display: flex;
						align-items: center;
						padding-top: 20rpx;
					}
					.time{
						font-size: 24rpx;
						font-weight: 400;
						color: #999999;
						line-height: 55rpx;
					}
				}
				.detlias_list_num{
					width: 30%;
					height: 100%;
					text-align: right;
					.fir{
						line-height: 85rpx;
						font-size: 30rpx;
						font-weight: 500;
					}
					.fir,.two{
						width: 100%;
						height: 50%;
						
					}
					.two{
						font-size: 24rpx;
						font-weight: 400;
						color: #999999;
					}
				}
				.num_red{
					color: #F05329;
				}
				.num_black{
					color: #000000;
				}
			}
		}
		.realName_box{
			width: 640rpx;
			height: 370rpx;
			background: #FFFFFF;
			.titl_box{
				width: 100%;
				height: 100rpx;
				display: flex;
				align-items: center;
				.name{
					width: 90%;
					height: 100%;
					text-align: center;
					line-height: 100rpx;
					font-size: 30rpx;
					font-weight: 500;
					color: #000000;
				}
			}
			.txt{
				width: 550rpx;
				height: 120rpx;
				margin: auto;
				font-size: 30rpx;
				font-weight: 500;
				color: #000000;
			}
			.btn_box{
				width: 560rpx;
				height: 70rpx;
				margin: auto;
				text-align: center;
				line-height: 70rpx;
				background: #F05329;
				border-radius: 10rpx;
				font-size: 30rpx;
				font-weight: 500;
				color: #FFFFFF;
			}
		}
	}
</style>
